package com.distributer.gateway.hander;

import java.util.concurrent.ConcurrentHashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BusinessHandler implements Handler{

	@Autowired
	private ConcurrentHashMap<String, BusinessThreadPool> handlerPools;
	
	@Override
	public void handle(BusinessTask businessTask) {
		BusinessThreadPool businessThreadPool = handlerPools.get(businessTask.getServiceName());
		if (businessThreadPool ==null) {
			throw new NullPointerException("根据serviceName="+businessTask.getServiceName()+"查询业务处理线程池失败！");
		}
		businessThreadPool.execute(businessTask);
	}

	@Override
	public BusinessThreadPool getBusinessThreadPool(String serviceName) {
		return handlerPools.get(serviceName);
	}

	@Override
	public void putBusinessThreadPool(String serviceName, BusinessThreadPool businessThreadPool) {
		handlerPools.put(serviceName, businessThreadPool);
	}

}
